const { rpc } = require('./util.js')
const regeneratorRuntime = require('./async.js')

module.exports = class Flow {
  constructor(handle, module) {
    this.handle = handle
    this.module = module
  }
  async dispatch(method, data = {}) {
    if (!this.module[method]) {
      throw `method: ${method}不存在`
    }
    await this.module[method](
      data,
      {
        dispatch: this.dispatch.bind(this),
        setData: value => {
          return new Promise(r => {
            this.handle.setState(value, r)
          })
        }
      },
      this.handle.data
    )
  }
}
